<template>
  <div>
    <el-form :model="tmList" :inline="true">
      <el-form-item label="一级菜单">
        <el-select placeholder="请选择一级菜单" v-model="tmList.category1Id" @change="cate1idchange" :disabled="show">
          <el-option :label="c1.name" :value="c1.id" v-for="(c1, index) in list1" :key="c1.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级菜单">
        <el-select placeholder="请选择二级菜单" v-model="tmList.category2Id" @change="cate2idchange" :disabled="show">
          <el-option :label="c1.name" :value="c1.id" v-for="(c1, index) in list2" :key="c1.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级菜单">
        <el-select placeholder="请选择三级菜单" v-model="tmList.category3Id" @change="cate3idchange" :disabled="show">
          <el-option :label="c1.name" :value="c1.id" v-for="(c1, index) in list3" :key="c1.id"></el-option>

        </el-select>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { Menu } from 'element-ui';

export default {
  name: 'menus',
  props: ['show'],
  data() {
    return {
      list1: [],
      list2: [],
      list3: [],
      tmList: {
        category1Id: "",
        category2Id: "",
        category3Id: "",
      }
    }
  },
  mounted() {
    this.getcatagory1()
  },
  methods: {
    async getcatagory1() {
      let res = await this.$API.attr.reqCategory1List()

      if (res.code == 200) {
        this.list1 = res.data
      }
    },
    async cate1idchange() {
      this.list2 = []
      this.list3 = []
      this.tmList.category2Id = ''
      this.tmList.category3Id = ''
      this.$emit("getcatagory", { categoryId: this.tmList.category1Id, level: 1 })
      let res = await this.$API.attr.reqCategory2List(this.tmList.category1Id);
      if (res.code == 200) {
        this.list2 = res.data
      }

    },
    async cate2idchange() {
      this.list3 = []
      this.tmList.category3Id = ''
      this.$emit("getcatagory", { categoryId: this.tmList.category2Id, level: 2 })
      let res = await this.$API.attr.reqCategory3List(this.tmList.category2Id);
      if (res.code == 200) {
        this.list3 = res.data
      }


    },
    async cate3idchange() {

      this.$emit("getcatagory", { categoryId: this.tmList.category3Id, level: 3 })
    }

  }
}
</script>

<style></style>